﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using VSSAHT.DataAccess;
using VSSAHT.Transfer;
namespace VSS_AHT.Forms
{
    public partial class FormRoles : BaseForm
    {
        #region Singleton Members
        private static volatile FormRoles instance;
        private static object syncRoot = new Object();

        public static FormRoles Instance
        {
            get
            {
                lock (syncRoot)
                {
                    if (instance == null)
                        instance = new FormRoles();
                }

                return instance;
            }
        }
        #endregion
        
        #region Field Members
        RoleDataAccess _dataAccess = new RoleDataAccess();

        IList<RoleDTO> _roleList;
        #endregion

        #region Ctors
        public FormRoles()
        {
            InitializeComponent();
            Initializes();
        }
        public void Initializes()
        {

          
            this.btnEdit.Click += new EventHandler(delegate { ClickButtonEdit(); });

            this.btnClose.Click += new EventHandler(delegate { this.Close(); });
            this.Disposed += new EventHandler(delegate { instance = null; });
            this.ClickButtonSearch();

        }
        #endregion

        #region Methods
        private void ClickButtonSearch()
        {
            _dataAccess.SearchObject = new RoleDTO();
            _dataAccess.SearchObject.RoleCode = "";


            _roleList = _dataAccess.Search();

            this.gridControl1.DataSource = _roleList; ;

        }

        private void ClickButtonEdit()
        {
            if (this.gridView1.GetFocusedRow() == null)
            {
                Common.ShowAlert("Vui lòng cho dòng cần chỉnh sửa");
                return;
            }

            // Edit  information
            FormUpdateRole instance = new FormUpdateRole();
            instance.Role = this.gridView1.GetFocusedRow() as RoleDTO;
            DialogResult result = instance.ShowDialog();
            if (result == DialogResult.OK)
            {
                // Refresh data
                this.gridView1.RefreshData();
            }

        }
        #endregion

    }
}